var express = require("express");
var router = express.Router();
var readInfoService = require("../../service/blog/readInfoService");

//获取read
router.get(
    "/get",
    async (req, res, next) => {
        let list = await readInfoService.query();
        res.json({ code: 1, data: list });
    },
    (err) => {
        res.json({ code: 0, msg: err });
    }
);
//修改read
router.post(
    "/update",
    async (req, res, next) => {
        let path = req.body.path;
        let list = await readInfoService.query({ path });
        if (!list.length) {
            readInfoService.add({ path, number: 0 });
        } else {
            let info = list[0];
            info.number += 1;
             await readInfoService.update(info);
        }
        res.json({ code: 1, data: "更新成功" });
    },
    (err) => {
        res.json({ code: 0, msg: err });
    }
);
module.exports = router;
